import * as sdk from './fetch';

/**
 * 查询游戏信息接口
 * @param params
 * @returns
 */
async function getGameIpConfigInfo(params = {}): Promise<any> {
  let result = await sdk.post<any>(`game-base-config/getByGameType`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询赠送游戏次数
 */
async function getGameTimesReceiveDaily(params = {}): Promise<any> {
  let result = await sdk.post<any>(`customergamecount/daily-gift`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询游戏可用次数
 */
async function getGameTimesConfigInfo(params = {}): Promise<any> {
  console.log('syntheticCardController getGameTimesConfigInfo params', params);
  let result = await sdk.post<any>(`customergamecount/find-current-user-available-game-count`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 非会员赠送游戏次数
 * @param params
 * @returns
 */
async function giveGameTimesNoVip(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`customergamecount/daily-gift-no-vip`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }

  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询是否是新人
 * @param params
 * @returns
 */
async function userComputedGameTimes(params = {}): Promise<any> {
  let result = await sdk.post<any>(`customergamecount/find-current-user-waste-game-count`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 是否是新人保障
 * @param params
 * @returns
 */
async function userIsNewComer(params = {}): Promise<any> {
  console.log('syntheticCardController userIsNewComer params', params);
  let result = await sdk.post<any>(`game-base-config/isNewcomer`, {
    ...params,
  });
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询榜单
 * @param params
 * @returns
 */
async function getRankingItems(params = {}): Promise<any> {
  console.log('syntheticCardController userIsNewComer params', params);

  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.post<any>(`leaderboard/charts`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }

  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询游戏配置信息
 * @param params
 * @returns
 */
async function getGameGrticleInfo(params = {}): Promise<any> {
  let result = await sdk.get<any>(`coinrain/getInfo`, {
    ...params,
  });
  console.log('goldCoinsController getGameGrticleInfo result', result);
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 查询魔力豆明细
 * @param params
 * @returns
 */
async function getGameCoinDetailByPage(params = {}): Promise<any> {
  let result = await sdk.post<any>(`coinrain/getMagicBeanPage`, {
    ...params,
  });
  console.log('goldCoinsController getGameGrticleInfo result', result);
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 兑换列表
 * @param params
 * @returns
 */
async function getGamePrizeList(params = {}): Promise<any> {
  let result = await sdk.get<any>(`coinrain/getPrizeList`, {
    ...params,
  });
  console.log('goldCoinsController getGamePrizeListByPage result', result);
  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

/**
 * 兑换礼品
 * @param params
 * @returns
 */
async function exchangePrize(params = {}): Promise<any> {
  let result = {
    context: '',
    code: '',
    message: '',
  };
  try {
    result = await sdk.get<any>(`coinrain/exchange/${params.id}`, {
      ...params,
    });
  } catch (e) {
    result = e;
  }

  return {
    data: result.context,
    code: result.code,
    message: result.message,
  };
}

export default {
  getGameTimesReceiveDaily,
  getGameTimesConfigInfo,
  userIsNewComer,
  getGameIpConfigInfo,
  userComputedGameTimes,
  getRankingItems,
  getGameGrticleInfo,
  getGameCoinDetailByPage,
  getGamePrizeList,
  exchangePrize,
  giveGameTimesNoVip,
};
